class Solarsystem < ActiveRecord::Base
  belongs_to :region
  belongs_to :constellation
  has_and_belongs_to_many :gates, :join_table => "solarsystems_jumps", :class_name => "Solarsystem", :association_foreign_key => :jump_id


  def self.search(query)
    self.find_by_name(query)
  end
	
	def self.find_by_region(region)
		id = Region.find_all([ 'LOWER(name) LIKE  ?', '%' + region.downcase + '%' ])
		self.find_all([ 'region_id = ' + id.first.id.to_s ])
	end

  def lowsec?
    return (self.security*10).round.to_f/10 < 0.5 ? true : false
  end
  
  def zerozero?
    return (self.security*10).round.to_f/10 == 0 ? true : false
  end
  
  def highsec?
    return (self.security*10).round.to_f/10 >= 0.5 ? true : false
  end

  def self.zero
		s = Solarsystem.find(:all, :conditions => "hub = 0 AND corridor = 0 AND region_id = 10000003");
		s.each do |sys|
			#print sys.name;
			end
	end

end
